<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
    
    var arr1=[];
    var number = 1;
    function fn(n, flag) {
        if (flag<= 0)
            return;
        var arr=new Array(n);
        for (var i = 0; i < n; i++) {
                arr[i] = number++;
        }
        
        arr1.push(arr);
        
        fn(n, --flag);   
        return arr1;
    }
    //  console.log(fn(10, 10))
    function f (str){
        console.log(str);
        
        for(var i=0;i<str.length;i++){
            var res='';
            for(var j=0;j<=i;j++)
            {
                res+=str[i][j]+" ";             
            }
            console.log(res);
        }
    }
    f(fn(5,5))
    </script>
</body>
</html>